package com.hh.hot100;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * @Author hanghao
 * @Date 2023/7/3 11:19
 * @Version 1.0
 * 二叉树的中序遍历
 * easy
 */

public class No94 {
    public List<Integer> inorderTraversal(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if(root == null) return res;
        Stack<TreeNode> stack = new Stack<>();
        TreeNode cur = root;
        while(cur != null || !stack.isEmpty()) {
            if(cur != null) {
                stack.add(cur);
                cur = cur.left;
            } else {
                cur = stack.pop();
                res.add(cur.val);
                cur = cur.right;
            }
        }
        return res;
    }

}
